home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / vdl020d.zip / DASDHIGH.DOC < prev    next >
Text File  |  1993-04-14  |  18KB  |  457 lines

  1.  
  2.  (*===================    D A S D   H I G H   U N I T  =====================
  3.   =                                                                        =
  4.   =  REVISION 1.0                 07/16/90                    J.R. TAYLOR  =
  5.   =                                                                        =
  6.   ==========================================================================
  7.   =                                                                        =
  8.   =  Sequential Access Device Management Library for SDLP                  =
  9.   =                                                                        =
  10.   =  Written By Jonathan Robert Taylor                                     =
  11.   =                                                                        =
  12.   =  This code is the property of columbia data products, Inc.             =
  13.   =  It may be distributed and used outside CDP so long as this header     =
  14.   =  remains intact and unmodified, and as long as it is used with a       =
  15.   =  licensed Standard Device Level Protocol Kernel.                       =
  16.   =                                                                        =
  17.   =  Copyright 1989,1990 Columbia Data Products                            =
  18.   =  ALL RIGHTS RESERVED                                                   =
  19.   =                                                                        =
  20.   = ---------------------------------------------------------------------- =
  21.   =  Revision History        Procedures changed; overall purpose of change.=
  22.   =                          Procedure specific revision notes below.       =
  23.   =                          Reverse chronological order.           =
  24.   = ---------------------------------------------------------------------- =
  25.   =   date    initials   change description                   =
  26.   = ---------------------------------------------------------------------- =
  27.   = 12-25-90    jrt     Started                                            =
  28.   =                                                                        =
  29.   ==========================================================================
  30. *)
  31.  
  32.  
  33. Unit DASDHIGH;
  34.  
  35. {-------------------------------------------------------------------------}
  36. {                       Unit DASDhigh                                     }
  37. {-------------------------------------------------------------------------}
  38. { PURPOSE: This provides a simple means of addressing DASD devices and    }
  39. { utilizing their data.  All data is actually part of the Dev structure   }
  40. { list but pointed to by the DASD device list.                            }
  41. { SOURCE: JR Taylor, Steve Lewis, Loren Grayson                           }
  42. {-------------------------------------------------------------------------}
  43.  
  44.  
  45. Uses
  46.  
  47.   VTypes,
  48.   DOS,
  49.   VSDLPLOW,
  50.   SDLPHIGH;
  51.  
  52. Type
  53.  
  54.  
  55.   {--------------------------------------------------}
  56.   { Drivelist -- a generic list for selecting drives }
  57.   {--------------------------------------------------}
  58.  
  59.   DriveList = Array[1..9] of INTEGER;
  60.  
  61.   {-----------------------------------------------}
  62.   { ParInfo -- Information for a SDPS 1 partition }
  63.   {-----------------------------------------------}
  64.  
  65.   ParInfo = RECORD
  66.     TypeNum     : WORD;
  67.     StartBlock  : LONGINT; {This is in Units of 8K bytes}
  68.     EndBlock    : LONGINT;
  69.     Status      : BYTE;
  70.     Reserved    : WORD;
  71.     SpecVer     : BYTE;
  72.     MachineType : WORD;
  73.     LocalStore  : Array[0..31] of CHAR;
  74.     ExtLocalStore:Array[32..128] of BYTE;
  75.   END;
  76.  
  77.   {-------------------------------------------}
  78.   { ParTable -- An entire drive of partitions }
  79.   {-------------------------------------------}
  80.  
  81.   ParTable = Array[1..32] of ParInfo;
  82.   PtrToParTable = ^ParTable;
  83.  
  84.  
  85.   {----------------------------------------}
  86.   { SDPS 1 Partition Table physical layout }
  87.   {----------------------------------------}
  88.  
  89.   SDPS1_PT_ENTRY=RECORD
  90.  
  91.     ParType       : WORD;
  92.     StartBlock    : LONGINT;
  93.     EndBlock      : LONGINT;
  94.     Status        : BYTE;
  95.     Reserved      : WORD;
  96.     SpecVer       : BYTE;
  97.     MachineType   : WORD;
  98.  
  99.   END;
  100.  
  101.   SDPS1_PT=Array[1..32] of SDPS1_PT_ENTRY;
  102.  
  103.   PtrToSDPS1_PT=^SDPS1_PT;
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110. Var
  111.  
  112.   DASD     : Array[1..64] of PtrToSDLPDev;
  113.  
  114.   DP1      : Array[1..64] of PtrToParTable;
  115.  
  116.   NumDASD  : WORD;
  117.  
  118.   DasdZ    : INTEGER;
  119.  
  120.   ParBlock : WORD;
  121.  
  122.  
  123. Procedure GetPartInfo(X: INTEGER);
  124.  
  125. Procedure MakeDASDList;
  126.  
  127.  
  128. Function  InitSDPS_1(UnitNum : BYTE) :BYTE;
  129.  
  130. Function  GetParEnd(P : POINTER) :BYTE;
  131.  
  132. Function  GetEnd8K(Par : INTEGER;
  133.                    P   : POINTER) :LONGINT;
  134.  
  135. Function  GetStart8K(Par,
  136.                      ParCount : INTEGER;
  137.                      Total8K  : LONGINT;
  138.                      P        : POINTER) :LONGINT;
  139.  
  140. Function  GetParSpace(Pos,Par,
  141.                       ParCount : INTEGER;
  142.                       Total8K  : LONGINT;
  143.                   VAR Start8K  : LONGINT;
  144.                       P        : POINTER) :LONGINT;
  145.  
  146. Function  CreateParEntry(Pos        : INTEGER;
  147.                          P          : ParInfo;
  148.                          TotalBytes : REAL;
  149.                          UnitNum    : BYTE) :WORD;
  150.  
  151.  
  152. ──────────────────────────────────────────────────────────────────────────────
  153.  
  154. Function GetParSpace(Pos,Par,
  155.                      ParCount : INTEGER;
  156.                      Total8K  : LONGINT;
  157.                  VAR Start8K  : LONGINT;
  158.                      P        : POINTER) :LONGINT;  {OLD}
  159. type
  160.   ARR1024 = ARRAY[1..1024] of BYTE;
  161. var
  162.   Datap  : ^ARR1024;
  163.   Avail8K,
  164.   ST,Ed  : LONGINT;
  165. begin
  166.   Datap:=P;
  167.   if (Pos=-1) then
  168.     begin  {appending}
  169.     ST:=GetEnd8K((Par-1),Datap);
  170.     ED:=Total8K;
  171.     end
  172.   else
  173.     begin  {inserting}
  174.     ST:=GetEnd8K((Par-1),Datap);
  175.     ED:=GetStart8K((Par+1),ParCount,Total8K,Datap);
  176.     end;
  177.  
  178.   Start8K:=ST;
  179.  
  180. {  ST:=(8192 div 512) * ST;    }
  181. {  ED:=(8192 div 512) * ED - 1;}
  182.  
  183.   GetParSpace:=Ed-St;
  184. end;
  185.  
  186.  
  187. {-------------------------------------------------------------------------}
  188. {                       Function CreateParEntry                           }
  189. {-------------------------------------------------------------------------}
  190. { IN:  Pos (INTEGER) desired position (1-30) or                           }
  191. {                           -1 = append data to current Par Table         }
  192. {      P (ParInfo) partition information                                  }
  193. {      TotalBytes (REAL) total bytes available on target drive            }
  194. {      UnitNum (BYTE) target drive                                        }
  195. { OUT: (WORD) action error code                                           }
  196. {               $00 - success, else                                       }
  197. {               $xx - $FE = No Table Room,                                }
  198. {                     $FD = Disk Space Error                              }
  199. {                           (NOT Avail or Allowed).                       }
  200. {                     $FC = Request Beyond Current Par List               }
  201. {                     $FB = Position Request Error                        }
  202. {              else   $xx = SDLP Error/Status Code                        }
  203. { This function creates a new Partition Table Entry in the requested      }
  204. { position.  If this is not possible, the appropriate error code is       }
  205. { returned.                                                               }
  206. {-------------------------------------------------------------------------}
  207. Function CreateParEntry(Pos        : INTEGER;
  208.                         P          : ParInfo;
  209.                         TotalBytes : REAL;
  210.                         UnitNum    : BYTE) :WORD;
  211. type
  212.   BLine = ARRAY[0..15] of BYTE;
  213. var
  214.   Len,
  215.   Free8K,
  216.   Total8K,
  217.   Start8K,
  218.   End8K,
  219.   PosSpace : LONGINT;
  220.   PT       : BLine;
  221.   Par,
  222.   ParCount : INTEGER;
  223.   R        : REAL;
  224.   Error,
  225.   Residue  : BYTE;
  226.   Block    : ARRAY[1..1024] of BYTE;
  227.   i        : INTEGER;
  228. begin
  229. (*CHECK IF POSITION IN RANGE*)
  230.   if (Pos>=-1) and (Pos<31) and (Pos<>0) then
  231.     begin
  232.     Par:=Pos;
  233.     Total8K:=trunc(TotalBytes/8192);
  234.  
  235. (*GET PARTITION BLOCK*)
  236.     SDLP_Read(Unitnum,addr(Block),1,0,Error,Residue);
  237.     if (Error=$00) then
  238.       begin
  239.       ParCount:=GetParEnd(addr(Block));
  240.  
  241. (*CHECK IF PARTITION REQUEST BEYOND CURRENT TABLE*)
  242.       if ((Pos>0) and (Pos<=ParCount+1)) or (Pos=-1) then
  243.         begin
  244.  
  245. (*CHECK IF POSITION APPEND*)
  246.         If (Pos=-1) then
  247.           Par:=ParCount+1;
  248.  
  249. (*IF ROOM IN TABLE, THEN CREATE PAR ENTRY*)
  250.         if (Par<31) then
  251.           begin
  252.  
  253. (*CHECK REQUEST SIZE WITH REMAINING SPACE ON DRIVE*)
  254.  
  255.           {Must make sure this is in terms of 8K Units}
  256.           Len:=(P.EndBlock - P.StartBlock) div (8192 div 512);
  257.  
  258.           PosSpace:=GetParSpace(Pos,Par,ParCount,Total8K,Start8K,addr(Block));
  259.  
  260. (*AND ROLL IF WE HAVE ENOUGH SPACE TO GO*)
  261.           if (Len<=PosSpace) then
  262.             begin
  263.             End8K:=Start8k + Len;
  264.  
  265.             fillchar(pt,sizeof(pt),$00);
  266.  
  267.             pt[ 0]:=P.TypeNum mod 256;
  268.             pt[ 1]:=P.TypeNum div 256;
  269.             pt[ 2]:=(Start8K mod 65536) mod 256; {ST}
  270.             pt[ 3]:=(Start8K mod 65536) div 256; {  }
  271.             pt[ 4]:=(Start8K div 65536) mod 256; {  }
  272.             pt[ 5]:=(Start8K div 65536) div 256; {ST}
  273.             pt[ 6]:=(End8K mod 65536) mod 256;   {ED}
  274.             pt[ 7]:=(End8K mod 65536) div 256;   {  }
  275.             pt[ 8]:=(End8K div 65536) mod 256;   {  }
  276.             pt[ 9]:=(End8K div 65536) div 256;   {ED}
  277.             pt[10]:=P.Status;
  278.             pt[11]:=P.Reserved mod 256;
  279.             pt[12]:=P.Reserved div 256;
  280.             pt[13]:=P.SpecVer;
  281.             pt[14]:=P.MachineType mod 256;
  282.             pt[15]:=P.MachineType div 256;
  283.  
  284.             SDLP_Read(UnitNum,addr(Block),1,0,Error,Residue);
  285.             if (Error=$00) then
  286.               begin
  287.               for i:=0 to 15 do
  288.                 Block[((Par-1)*16)+i]:=pt[i];
  289.               SDLP_Write(UnitNum, addr(Block),1,0,Error,Residue);
  290.               end;
  291.  
  292.             if (Error=$00) then
  293.               begin
  294.               SDLP_Read(UnitNum,addr(Block),1,Par,Error,Residue);
  295.               if (Error=$00) then
  296.                 begin
  297.                 for i:=0 to 31 do
  298.                   Block[i]:=BYTE(P.LocalStore[i]);
  299.                 for i:=32 to 98 do
  300.                   Block[i]:=P.ExtLocalStore[i];
  301.                 SDLP_Write(UnitNum,addr(Block),1,Par,Error,Residue);
  302.                 end;
  303.               end;
  304.             CreateParEntry:=Error; {EITHER SUCCESS, OR READ/WRITE ERROR}
  305.             end
  306.           else
  307.             CreateParEntry:=$FD;  {ILLEGAL SPACE REQUEST -NOT ENOUGH/ POS>AVAIL}
  308.           end
  309.         else
  310.           CreateParEntry:=$FE;  {NO PARTITION TABLE ROOM}
  311.         end
  312.       else
  313.         CreateParEntry:=$FC;  {ILLEGAL REQUEST -REQUEST BEYOND LIST}
  314.       end
  315.     else
  316.       CreateParEntry:=Error;  {ERROR IN READ OPERATION}
  317.     end
  318.   else
  319.     CreateParEntry:=$FB;  {POSITION REQUEST ERROR}
  320. end;
  321.  
  322.  
  323. (*========================================================================
  324.     HAD TO COMMENT THIS AREA OUT TO COMPILE
  325.     AS NONE OF THESE SEEM TO BE IMPLEMENTED YET --LG
  326.  
  327.  
  328. {-------------------------------------------------------------------------}
  329. {                       Function DH_GetParMethod  (INCOMPLETE)            }
  330. {-------------------------------------------------------------------------}
  331. { IN:  DriveNum (WORD) target drive number                                }
  332. { OUT: (BYTE) partition type code (or error)                              }
  333. {                 $00 = unknown                                           }
  334. {                 $01 = SDPS                                              }
  335. {                 $02 = SDPS-2                                            }
  336. {                 $80 = FDISK                                             }
  337. { determines what type of partitioning is being used on the target device }
  338. {-------------------------------------------------------------------------}
  339. Function DH_GetParMethod(    DriveNum : WORD          ) : BYTE;
  340.  
  341. { returns partitioning method of the selected drive }
  342. { 0 = unknown, 1=sdps 1, 2=sdps2, $80 = FDISK       }
  343. { FF= error reading drive                           }
  344.  
  345.  
  346. {-------------------------------------------------------------------------}
  347. {                       Function DH_GetBlockNum  (INCOMPLETE)             }
  348. {-------------------------------------------------------------------------}
  349. { IN:  DriveNum (WORD) target drive number                                }
  350. {      ParNum (WORD)      ??                                              }
  351. {      ParBlock (LONGINT) ??                                              }
  352. { OUT: (LONGINT)          ??                                              }
  353. { returns logical block number for block "ParBlock" in partition "ParNum" }
  354. { on drive DriveNum.                                                      }
  355. {-------------------------------------------------------------------------}
  356.  
  357.  
  358. Function DH_GetBlockNum(     DriveNum : WORD;
  359.                              ParNum   : WORD;
  360.                              ParBlock : LONGINT       ) : LONGINT;
  361.  
  362. { returns logical block number for block "ParBlock" in }
  363. { partition "ParNum" on drive DriveNum                 }
  364.  
  365. {-------------------------------------------------------------------------}
  366. {                       Procedure DH_ReadPT1  (INCOMPLETE)                }
  367. {-------------------------------------------------------------------------}
  368. { IN:  DriveNum (WORD) target drive number                                }
  369. {      LSNum (WORD) Local Store Number (???)                              }
  370. {      Buff (POINTER) pointer to block data buffer                        }
  371. { OUT: (none)                                                             }
  372. { Reads SDPS-1 Partition Table                                            }
  373. {-------------------------------------------------------------------------}
  374.  
  375. Procedure DH_ReadPT1(         DriveNum : WORD;
  376.                               LSNum    : WORD;
  377.                               Buff     : POINTER;
  378.                               Err      : WORD         );
  379.  
  380. { Read SDPS1 partition table }
  381.  
  382. {-------------------------------------------------------------------------}
  383. {                       Procedure DH_WritePT1  (INCOMPLETE)               }
  384. {-------------------------------------------------------------------------}
  385. { IN:  DriveNum (WORD) target drive number                                }
  386. {      LSNum (WORD) Local Store Number (???)                              }
  387. {      Buff (POINTER) pointer to block data buffer                        }
  388. {      Err (WORD) error code (should be VAR!!!)                           }
  389. { OUT: (none)                                                             }
  390. { Write SDPS-1 Partition Table                                            }
  391. {-------------------------------------------------------------------------}
  392.  
  393. Procedure DH_WritePT1(        DriveNum : WORD;
  394.                               LSNum    : WORD;
  395.                               Buff     : POINTER;
  396.                               Err      : WORD         );
  397.  
  398.  
  399. { Write SDPS1 Partition Table }
  400.  
  401. {-------------------------------------------------------------------------}
  402. {                       Procedure DH_ReadLS1  (INCOMPLETE)                }
  403. {-------------------------------------------------------------------------}
  404. { IN:  DriveNum (WORD) target drive number                                }
  405. {      LSNum (WORD) Local Store number (???)                              }
  406. {      Buff (POINTER) pointer to block data buffer                        }
  407. {      Err (WORD) error code (should be VAR!!!)                           }
  408. { OUT: (none)                                                             }
  409. { Reads SDPS-1 Local Store                                                }
  410. {-------------------------------------------------------------------------}
  411.  
  412. Procedure DH_ReadLS1(         DriveNum : WORD;
  413.                               LSNum    : WORD;
  414.                               Buff     : POINTER;
  415.                               Err      : WORD         );
  416.  
  417. { Read SDPS1 local store }
  418.  
  419. {-------------------------------------------------------------------------}
  420. {                       Procedure DH_WriteLS1  (INCOMPLETE)               }
  421. {-------------------------------------------------------------------------}
  422. { IN:  DriveNum (WORD) target drive number                                }
  423. {      LSNum (WORD) Local Store number (???)                              }
  424. {      Buff (POINTER) pointer to block data buffer                        }
  425. {      Err (WORD) error code (should be VAR!!!)                           }
  426. { OUT: (none)                                                             }
  427. { Writes SDPS-1 Local Store                                               }
  428. {-------------------------------------------------------------------------}
  429.  
  430. Procedure DH_WriteLS1(        DriveNum : WORD;
  431.                               LSNum    : WORD;
  432.                               Buff     : POINTER;
  433.                               Err      : WORD         );
  434.  
  435.  
  436. { Write SDPS1 Local Store }
  437.  
  438. *)
  439.  
  440.  
  441. {-------------------------------------------------------------------------}
  442. {                       Unit DASDhigh                                     }
  443. {-------------------------------------------------------------------------}
  444.  
  445. BEGIN
  446.   {---------------------------}
  447.   { init dasd list to nothing }
  448.   {---------------------------}
  449.   For DasdZ:=1 to 64 do
  450.   BEGIN
  451.     DASD[DasdZ]:=NIL;
  452.     DP1[DasdZ]:=NIL;
  453.   END;
  454.  
  455.   ParBlock := 0;
  456. END.
  457.